﻿using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace Scheduler.Business_Logic_Layer
{
    /**Class: GlobalDataManager
     * @author Sara Tuohy
     * @version 1.0
     * Course : ITEC 4860 Spring, 2012
     * Written: March, 2012
     * This class manages creating complex data types for the GlobalVariables class
     * Direct access is fine to check a boolean value, but creating the Employee list, for 
     * example, is code that should only have to be written once, but accessed from 
     * anywhere.
     */ 

    class GlobalDataManager
    {

        /**Method: CreateEmployeeList
         * Reads the DB for all entries and creates the list anew, then 
         * updates the GlobalVariables to make the list available.  
         * NOTE: Developer should check that 
         * Presentation_Layer.GlobalVariables.GlobalEmployeeListCompiled 
         * is false BEFORE calling for its creation.
         */ 
        public void CreateEmployeeList()
        {

            Data_Access_Layer.Employee employeeData = 
                new Data_Access_Layer.Employee(Presentation_Layer.GlobalVariables.GlobalLoggedInUser);
            ArrayList allEmployees = employeeData.getAllEmployees();
            Business_Logic_Layer.Employee[] EmployeeList = new Business_Logic_Layer.Employee[allEmployees.Count];
            int i = 0;
            foreach (ArrayList al in allEmployees)
            {
                string eid = (string)al[0].ToString();
                string name = (string)al[1].ToString();
                string phone = (string)al[2].ToString();
                string email = (string)al[3].ToString();   
                EmployeeList[i] = new Business_Logic_Layer.Employee(name, phone, email, eid);
                i++;
            }
            Presentation_Layer.GlobalVariables.GlobalEmployeeList = EmployeeList;
            Presentation_Layer.GlobalVariables.GlobalEmployeeListCompiled = true;           
        }

    }
}
